package com.omt.tarjimdinek.domain.translate.entity;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.Version;

import org.apache.log4j.Logger;

import com.google.common.base.Objects;
import com.omt.tarjimdinek.domain.islamicLibrary.entity.Fatwa;
import com.omt.tarjimdinek.domain.islamicLibrary.entity.Hadith;
import com.omt.tarjimdinek.domain.islamicLibrary.entity.Sahabi;
import com.omt.tarjimdinek.domain.islamicLibrary.entity.Verset;
import com.omt.tarjimdinek.support.Identifiable;

/**
 * fragment of text line
 * @author chabane
 */
@Entity
@Table(name="a01_lgnfgt")
public class LigneFragment  implements Identifiable<Long>, Serializable{

    private static final long serialVersionUID = 1L;
    private static final Logger log = Logger.getLogger(LigneFragment.class);
    
	/** ID SGBD */
	@Column(name="CNLGNFGT", length=11)
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long id;
	
	@Column(name = "VERSION", precision = 10)
    @Version
    private Integer version;
	
	/** a hadith of islam */
	@JoinColumn(name="CNHDT", nullable=false)
    @ManyToOne
	private Hadith hadith;
	
	/** a verse of quran */
	@JoinColumn(name="CNVST", nullable=false)
    @ManyToOne
	private Verset verset;
	
	/** a fatwa of cheikh*/
	@JoinColumn(name="CNFTW", nullable=false)
    @ManyToOne
	private Fatwa fatwa;
	
	/** a content of line */
	@Column(name="LICTN")
	private String contenu;
	
	/** line attached */
	@JoinColumn(name = "CNLGN", nullable = false)
	@ManyToOne
	private Ligne ligne;
	
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}
	
	public Hadith getHadith() {
		return hadith;
	}

	public void setHadith(Hadith hadith) {
		this.hadith = hadith;
	}

	public Verset getVerset() {
		return verset;
	}

	public void setVerset(Verset verset) {
		this.verset = verset;
	}

	public Fatwa getFatwa() {
		return fatwa;
	}

	public void setFatwa(Fatwa fatwa) {
		this.fatwa = fatwa;
	}

	public String getContenu() {
		return contenu;
	}

	public void setContenu(String contenu) {
		this.contenu = contenu;
	}
	
	public Ligne getLigne() {
		return ligne;
	}

	public void setLigne(Ligne ligne) {
		this.ligne = ligne;
	}

	@Transient
	public boolean isIdSet() {
		return id != null && id.compareTo(Long.valueOf(0)) != 0;
	}
	
	/**
     * equals implementation using a business key.
     */
    public boolean equals(Object other) {
        return this == other || (other instanceof Sahabi && hashCode() == other.hashCode());
    }

    public int hashCode() {
        int hashCode = Objects.hashCode(getId());
        return hashCode;
    }
    
    /**
     * Construct a readable string representation for this instance.
     * @see java.lang.Object#toString()
     */
    public String toString() {
        return Objects.toStringHelper(this) //
                .add("id", getId()) //
                .add("hadith", getHadith()) //
                .add("verset", getVerset()) //
                .add("fatwa", getFatwa()) //
                .add("contenu", getContenu()) //
                .add("version", getVersion()) //
                .toString();
    }
}
